﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Client
{
    public partial class GuiUserControl : Form
    {
        private UserCtlFront frontCtl;
        private UserCtlMovieSelect movieSelectCtl;
        private UserCtlSeats seatsCtl;
        private UserCtlReceipt receiptCtl;
        private UserCtlCustomer customerCtl;


        public GuiUserControl()
        {
            InitializeComponent();

            frontCtl = new UserCtlFront();
            frontCtl.InnerButtonClick += front_InnerButtonClick;

            panel1.Controls.Add(frontCtl);
            frontCtl.Dock = panel1.Dock;

            
        }
        private void front_InnerButtonClick(object sender, EventArgs e)
        {
            //MessageBox.Show("front_innerClick");
            customerCtl = new UserCtlCustomer(frontCtl.employee);

            customerCtl.InnerButtonClickProceed += customer_InnerButtonClickProceed;
            customerCtl.InnerButtonClickSearch += customer_InnerButtonClickSearch;
            customerCtl.InnerButtonClickCustomer += customer_InnerButtonClickCustomer;
            
            panel1.Controls.Remove(frontCtl);
            panel1.Controls.Add(customerCtl);

        }

        private void customer_InnerButtonClickCustomer(object sender, EventArgs e)
        {
            movieSelectCtl = new UserCtlMovieSelect(frontCtl.employee, customerCtl.customer);
            movieSelectCtl.InnerButtonClick += movieSelect_InnerButtonClick;
            panel1.Controls.Remove(customerCtl);
            panel1.Controls.Add(movieSelectCtl);
        }

        private void customer_InnerButtonClickProceed(object sender, EventArgs e)
        {
            movieSelectCtl = new UserCtlMovieSelect(frontCtl.employee, customerCtl.makeCheatCustomer());
            movieSelectCtl.InnerButtonClick += movieSelect_InnerButtonClick;
            panel1.Controls.Remove(customerCtl);
            panel1.Controls.Add(movieSelectCtl);
        }

        private void customer_InnerButtonClickSearch(object sender, EventArgs e)
        {
            //skal der være noget her ???? TODO
        }

        private void movieSelect_InnerButtonClick(object sender, EventArgs e)
        {
            //MessageBox.Show("movie_innerClick");
            //MessageBox.Show(movieSelect.newBooking.BookingId.ToString());
            seatsCtl = new UserCtlSeats(movieSelectCtl.booking, customerCtl.customer, frontCtl.employee);
            seatsCtl.InnerButtonClickReturn += seats_InnerButtonClickReturn;
            seatsCtl.InnerButtonClickConfirm += seats_InnerButtonClickConfirm;

            panel1.Controls.Remove(movieSelectCtl);
            panel1.Controls.Add(seatsCtl);
            seatsCtl.Dock = panel1.Dock;
            //MessageBox.Show(movieSelect.NewBooking.PbList[0].Id.ToString());
        }
        private void seats_InnerButtonClickReturn(object sender, EventArgs e)
        {
            panel1.Controls.Remove(seatsCtl);
            panel1.Controls.Add(movieSelectCtl);
            movieSelectCtl.Dock = panel1.Dock;
        }

        private void seats_InnerButtonClickConfirm(object sender, EventArgs e)
        {
            receiptCtl = new UserCtlReceipt(seatsCtl.booking, customerCtl.customer, seatsCtl.employee);
            receiptCtl.InnerButtonClickNewPartBooking += receipt_InnerButtonClickNewPartBooking;
            receiptCtl.InnerButtonClickNewBooking += receipt_InnerButtonClickNewBooking;
            panel1.Controls.Remove(seatsCtl);
            panel1.Controls.Add(receiptCtl);
            receiptCtl.Dock = panel1.Dock;
        }

        private void receipt_InnerButtonClickNewPartBooking(object sender, EventArgs e)
        {
            movieSelectCtl = new UserCtlMovieSelect(receiptCtl.booking, receiptCtl.employee, receiptCtl.customer);
            movieSelectCtl.InnerButtonClick += movieSelect_InnerButtonClick;
            panel1.Controls.Remove(receiptCtl);
            panel1.Controls.Add(movieSelectCtl);
            movieSelectCtl.Dock = panel1.Dock;
        }

        private void receipt_InnerButtonClickNewBooking(object sender, EventArgs e)
        {
            customerCtl = new UserCtlCustomer(receiptCtl.employee);
            customerCtl.InnerButtonClickProceed += customer_InnerButtonClickProceed;
            customerCtl.InnerButtonClickSearch += customer_InnerButtonClickSearch;
            customerCtl.InnerButtonClickCustomer += customer_InnerButtonClickCustomer;

            panel1.Controls.Remove(receiptCtl);
            panel1.Controls.Add(customerCtl);
            customerCtl.Dock = panel1.Dock;
        }
    }
}
